// $Id: to_str_w.cpp 2 2009-09-02 08:47:42Z joseph2002 $
/*
 * Copyright 2009 Joseph Wu
 * Distributed under the Boost Software License, Version 1.0.
 * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
 *
 * For more information, see http://xpcomplus.sourceforge.net
 */

#include <boost/test/unit_test.hpp>
#include <xpcom/uuid.hpp>
#include <xpcom/string.hpp>

#ifdef XPCOM_HAS_2BYTE_WCHAR_T

BOOST_AUTO_TEST_CASE(test_to_str_w)
{
    using namespace xpcom;

    // Parse success
    uuid id = { 0x64D47515, 0xADE3, 0xa5d1,
            { 0xAB, 0xAE, 0x3A, 0x93, 0x62, 0xC5, 0xA5, 0x51 } };

    const wstring id_str1(wstring::literal(L"64D47515-ADE3-a5d1-ABAE-3A9362C5A551"));
    const wstring id_str11 = L"{64D47515-ADE3-a5d1-ABAE-3A9362C5A551}";

    const wstring id_str2 = L"64d47515-ade3-a5d1-abae-3a9362c5a551";
    const wstring id_str21 = L"{64d47515-ade3-a5d1-abae-3a9362c5a551}";

    const wstring id_str3 = L"64D47515-ADE3-A5D1-ABAE-3A9362C5A551";
    const wstring id_str31 = L"{64D47515-ADE3-A5D1-ABAE-3A9362C5A551}";

    const wstring init_str = L"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx12XYZ";
    wstring id_str;

    id.to_str(id_str);
    BOOST_CHECK(id_str == id_str1);

    id.to_str(id_str, uuid::output_braces);
    BOOST_CHECK(id_str == id_str11);

    id_str.resize(2000, L'x');
    id.to_str(id_str, uuid::output_lower_case);
    BOOST_CHECK(id_str == id_str2);

    id_str.clear();
    id.to_str(id_str, uuid::output_braces | uuid::output_lower_case);
    BOOST_CHECK(id_str == id_str21);

    id.to_str(id_str, uuid::output_upper_case);
    BOOST_CHECK(id_str == id_str3);

    id_str = init_str;
    id.to_str(id_str, uuid::output_braces | uuid::output_upper_case);
    BOOST_CHECK(id_str == id_str31);

    // Lower case has priority
    id.to_str(id_str, uuid::output_lower_case | uuid::output_upper_case);
    BOOST_CHECK(id_str == id_str2);
    id.to_str(id_str, uuid::output_lower_case | uuid::output_upper_case | uuid::output_braces);
    BOOST_CHECK(id_str == id_str21);
}

#endif
